From: Philip Withnall Date: Thu, 20 Nov 2025 16:32:18 +0000 (+0000) Subject: parentalControlsManager: Add more helper methods X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~44^2~90 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=085af29a919f0eac00abd568c648ffa2dac91ca1;p=gnome-shell.git parentalControlsManager: Add more helper methods For working out whether any parental controls apply to the current user. These will be used in an upcoming commit. Signed-off-by: Philip Withnall Part-of: --- diff --git a/js/misc/parentalControlsManager.js b/js/misc/parentalControlsManager.js index f4b284120..267c37e5a 100644 --- a/js/misc/parentalControlsManager.js +++ b/js/misc/parentalControlsManager.js @@ -60,6 +60,12 @@ const ParentalControlsManager = GObject.registerClass({ 'app-filter-changed': {}, 'session-limits-changed': {}, }, + Properties: { + 'any-parental-controls-enabled': GObject.ParamSpec.boolean( + 'any-parental-controls-enabled', null, null, + GObject.ParamFlags.READABLE, + false), + }, }, class ParentalControlsManager extends GObject.Object { _init() { super._init(); @@ -78,6 +84,7 @@ const ParentalControlsManager = GObject.registerClass({ this._initialized = true; this.emit('app-filter-changed'); this.emit('session-limits-changed'); + this.notify('any-parental-controls-enabled'); return; } @@ -101,6 +108,7 @@ const ParentalControlsManager = GObject.registerClass({ this._initialized = true; this.emit('app-filter-changed'); this.emit('session-limits-changed'); + this.notify('any-parental-controls-enabled'); } async _getAppFilter() { @@ -131,6 +139,7 @@ const ParentalControlsManager = GObject.registerClass({ try { this._appFilter = await this._getAppFilter(); this.emit('app-filter-changed'); + this.notify('any-parental-controls-enabled'); } catch (e) { // Log an error and keep the old app filter. logError(e, `Failed to get new MctAppFilter for uid ${Shell.util_get_uid()} on app-filter-changed`); @@ -165,6 +174,7 @@ const ParentalControlsManager = GObject.registerClass({ try { this._sessionLimits = await this._getSessionLimits(); this.emit('session-limits-changed'); + this.notify('any-parental-controls-enabled'); } catch (e) { // Keep the old session limits logError(e, `Failed to get new MctSessionLimits for uid ${Shell.util_get_uid()} on session-limits-changed`); @@ -201,6 +211,30 @@ const ParentalControlsManager = GObject.registerClass({ return this._appFilter.is_appinfo_allowed(appInfo); } + /** + * Check whether parental controls app filtering is enabled for the account, + * and if the library supports the features required for the functionality. + * + * Typically you should check whether a certain app is filtered + * (shouldShowApp()), rather than checking whether filtering is enabled at + * all. + * + * @returns {bool} whether app filtering is supported and enabled. + */ + appFilterEnabled() { + // Are latest parental controls enabled (at configure or runtime)? + if (!HAVE_MALCONTENT_0_14 || this._disabled) + return false; + + // Have we finished initialising yet? + if (!this.initialized) { + console.debug('Ignoring app filter because parental controls not yet initialised'); + return false; + } + + return this._appFilter.is_enabled(); + } + /** * Check whether parental controls session limits are enabled for the account, * and if the library supports the features required for the functionality. @@ -220,4 +254,14 @@ const ParentalControlsManager = GObject.registerClass({ return this._sessionLimits.is_enabled(); } + + /** + * Whether any parental controls are supported and enabled for the current + * user. + * + * @type {bool} + */ + get anyParentalControlsEnabled() { + return this.appFilterEnabled() || this.sessionLimitsEnabled(); + } });